/****************************************************************************/
/* NAME:           led.h                                                    */
/* PURPOSE:        Leds pwm management                                      */
/* CREATED_BY:     Didsau                                                   */
/* CREATION_DATE:  18/08/2012                                               */
/************************************** (C) Copyright 2012 AquaLink *********/

#include "main.h"

/* Apply a global brightness on all LED, 75.0% */
#define GLOBAL_BRIGHTNESS                  (750)

typedef enum
{
  WHITE_LED,
  BLUE_LED,
  MOON_LED,
  RGB_LED         // Futur develepment :)
}LED_COLOR_T;

typedef struct
{
    uint8_t          id;                   /* id of light                              */
    uint8_t          time_start_HH;        /* Hours start                              */
    uint8_t          time_start_MM;        /* Minute start                             */
    uint8_t          time_stop_HH;         /* Hours stop                               */
    uint8_t          time_stop_MM;         /* Minute stop                              */
    uint16_t         led_brigtness;        /* max pwm 1000 -> 100%                     */
    bool             led_dimming_direction;/* Mode FALSE : Slope UP, TRUE : Slope DOWN */
    bool             forced;               /* if TRUE, active led with max value       */
    uint8_t          OutputName;           /* Name of out put                          */
    LED_COLOR_T      led_color;            /* Color of led for different curve         */
    bool             weatherCondition;     /* use weather condition or not             */
}Led_def_t;

/**
 * @brief  Main function of leds module.
 * @param  none
 * @retval None
 */
void vTaskCTRL_INTERPOLATED_LEDS_PWM();

/**
 * @brief  Return weather condition, should be run once per day
 * @param  None
 * @retval Return percent brightness, to apply at final brigtness of led
 */
uint8_t LED_getWeatherCondition(void);

/**
 * @brief  Return weather condition
 * @param  None
 * @retval Return percent brightness, after weather condition and cloud condition.
 */
uint32_t LED_ManageWeatherCondition(uint32_t PwmValueBeforeBrightness,
                                    uint8_t LedID);

/**
 * @brief  Compute brightness with interpolated value
 * @param  None
 * @retval None
 */
uint32_t LED_ComputeBrightnessBase(uint32_t IgnitionTime,
                                   uint32_t *TableInput,
                                   uint32_t *TableOutput,
                                   uint32_t SecondToInterpoled,
                                   uint8_t  TableSize);

/**
 * @brief  Compute ignition time to interpolation
 * @param  None
 * @retval None
 */
void LED_ComputeIgnitionTime(uint8_t ledID,
                             uint32_t TimeInSecond,
                             uint32_t *SecondToInterpoled,
                             uint32_t *IgnitionTime);

/**
 * @brief  Compute moon cycle
 * @param  None
 * @retval None
 */
uint8_t LED_ComputeMoonDay(uint32_t TimeInSecond);


